<template>
  <div class="app-container">
    <el-form :model="presentlist" :rules="rules" ref="presentlist" label-width="120px" class="demo-presentlist">
      <el-form-item label="商品名称:" prop="cname">
        <el-input v-model="presentlist.cname" style="width: 450px"></el-input>
      </el-form-item>
      <el-form-item label="商品积分价格:" prop="money">
        <el-input v-model="presentlist.money" style="width: 450px"></el-input>
      </el-form-item>
      <el-form-item label="商品类型:">
        <el-select placeholder="请输入商品类型" v-model="presentlist.ctype" style="width: 450px">
          <!--需要添加v-model绑定数据 v-model="formInline.acptsiteid"-->
          <el-option label="实体物品" value="0"></el-option>
          <el-option label="虚拟物品" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品数量:" prop="number">
        <el-input v-model="presentlist.number" style="width: 450px"></el-input>
      </el-form-item>
      <el-form-item label="描述:" prop="cdescribe">
        <el-input type="textarea" v-model="presentlist.cdescribe" style="width: 450px"></el-input>
      </el-form-item>
      <el-upload
          action="#"
          list-type="picture-card"
          :auto-upload="false" style="margin-left: 120px">

        <i slot="default" class="el-icon-plus"></i>

        <div slot="file" slot-scope="{file}">
          <img
              class="el-upload-list__item-thumbnail"
              :src="file.url" alt="file.url"
          >
        </div>
      </el-upload>
      <!--    <el-dialog :visible.sync="dialogVisible">-->
      <!--      <img width="100%" :src="dialogImageUrl" alt="aaaa">-->
      <!--    </el-dialog>-->
      <div style="margin-top: 20px">
        <el-form-item>
          <el-button type="primary" @click="submitForm('presentlist')">添加</el-button>
          <el-button @click="resetForm('presentlist')">重置</el-button>
        </el-form-item>
      </div>

    </el-form>
  </div>
</template>
<script>
import hospitalSetApi from "@/api/integral";

export default {
  data() {
    return {
      dialogImageUrl: '',
      dialogVisible: false,
      disabled: false,
      presentlist: {
        cname: '',//商品名称
        money: '',//商品积分价格
        ctype: '',//商品类型(实体物体0,虚拟1)
        number: '',//商品数量
        cdescribe: '',//描述
        image: ''//图片
      },
      rules: {
        cname: [
          {required: true, message: '请输入商品名称', trigger: 'blur'},
        ],
        money: [
          {required: true, message: '请输入商品积分价格', trigger: 'blur'},
        ],
        ctype: [
          {required: true, message: '请选择商品类型', trigger: 'change'},
        ],
        number: [
          {required: true, message: '请输入商品数量', trigger: 'blur'},
        ],
        cdescribe: [
          {required: true, message: '请输入描述', trigger: 'blur'},
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        hospitalSetApi.findInsertCommodity(this.presentlist).then(res => {
          console.log(res)
          if (res.data == true) {
            this.$message({
              type: 'success',
              message: '添加成功!',
            });
          } else {
            this.$message({
              type: 'defeated',
              message: '添加失败!',
            });
          }
        })
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>
